<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <!-- <link href="./Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet"> -->
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
	    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
	    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
	    <script type="text/javascript">
	        $(function() {
	            $('#f').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeDesc' : '上传文件',//上传描述
	                'fileTypeExts' : '*.jpg;*.png',
	                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
	                'uploader' : '{{U('upload')}}',//指定服务器上传的方法
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 10,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li style='list-style:none;float:left'>";
	                    li += "<img src='"+imageUrl+"' width='100px'/>";
	                    li += "<a href='javascript:;' class='close_img'>×</a>";
	                    li += "<input type='hidden' name='listView[]' value='"+data.path+"'/>";
	                    li += "</li>";
	                    $("#uploadList ul").prepend(li);
	                }
	            });
				$('#fi').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeDesc' : '上传文件',//上传描述
	                'fileTypeExts' : '*.jpg;*.png',
	                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
	                'uploader' : '{{U('upload')}}',//指定服务器上传的方法
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 10,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
	                    //转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li style='list-style:none;float:left'>";
	                    li += "<img src='"+imageUrl+"' width='100px'/>";
	                    li += "<a href='javascript:;' class='close_img'>×</a>";
	                    li += "<input type='hidden' name='img[]' value='"+data.path+"'/>";
	                    li += "</li>";
	                    $("#uploadListf ul").prepend(li);
	                }
	            });
				$('.category').change(function() {
						var tid = $("option:selected").attr('tid');
						$.ajax({
							url:"{{U('./Admin/Goods/add')}}",
							type:'get',
							data:{tid:tid},
							dataType:'json',
							success:function(data){
								var attr = data.attr;
								var spec = data.spec;
								var attrstr = '';
								var specstr = '';
								$.each(attr,function(k, v) {
									var value = v.value.split('|');
									var str = '<tr>';
									str += '<td>' + v.aname + '</td>';
									str += "<td><select class='form-control btn-block' name='goodsvalue["+v.aid+"]'>";
									$.each(value,function(kk, vv) {

										str += '<option value="'+ vv +'">'+vv+'</option>';
									});
									str += '</select></td></tr>';
									attrstr += str;
								});
								$('#tAttr').html(attrstr);

								$.each(spec,function(k, v) {

									var value = v.value.split('|');
									var str = '<tr>';
									str += '<td>' + v.aname + '</td>';
									str += "<td><select class='form-control btn-block' name='goodsvalue["+v.aid+"][]'>";
									$.each(value,function(kk, vv) {
										str += '<option>'+vv+'</option>';
									});
									str += '</select></td>';
									str += '<td><span>附加价格</span><input type="text" name="added['+v.aid+'][]" /><button type="button" id="btn">添加规格</button></td>';
									str += '</tr>';
									specstr += str;
								});
								$('#tSpec').html(specstr);
							}
						})
				});
				$(document).on('click', '#btn', function(event) {
					$('#tSpec').append($(this).parent().parent().clone());
				});

				$(document).on('click', '.close_img', function(event) {
					$(this).parent('li').remove();
				});
	        });
	    </script>
	</head>
	<body>
		<form action="" method="post" enctype="multipart/form-data">
			<div class="alert alert-success">添加商品</div>
			<div class="form-group">
				<label for="exampleInputEmail1">所属分类</label>
				<select name="category_cid" class="form-control category">
					<option value="0">请选择</option>
					{{foreach from="$category" value="$v"}}
					<option tid="{{$v['type_tid']}}" value="{{$v['cid']}}|{{$v['type_tid']}}" {{if value="$goodsData['category_cid'] eq $v['cid']"}}selected="selected"{{endif}}>{{$v['_name']}}</option>
					{{endforeach}}
				</select>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">所属品牌</label>
				<select name="brand_bid" class="form-control">
					<option value="">请选择</option>
					{{foreach from="$brand" value="$v"}}
					<option value="{{$v['bid']}}" {{if value="$goodsData['brand_bid'] eq $v['bid']"}}selected="selected"{{endif}}>{{$v['bname']}}</option>
					{{endforeach}}
				</select>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商品属性</label>
				<table id="tAttr">
				{{foreach from="$goodsAttrData" value="$v"}}
					{{if value="$v['attr'] eq 0"}}
					<tr>
						<td>{{$v['aname']}}</td>
						<td>
							<select name="goodsvalue[{{$v['type_tid']}}]" id="" class='form-control btn-block'>
								<option value="{{$v['gaid']}}">{{$v['goodsvalue']}}</option>
							</select>
						</td>
					</tr>
					{{endif}}
				{{endforeach}}
				</table>
				<label for="exampleInputEmail1">商品规格</label>
				<table id="tSpec">
				{{foreach from="$goodsAttrData" value="$v"}}
					{{if value="$v['attr'] eq 1"}}
					<tr class="tr">
						<td>{{$v['aname']}}</td>
						<td>
							<select name="goodsvalue[{{$v['type_tid']}}][]" id="" class='form-control btn-block'>
								<option value="{{$v['gaid']}}">{{$v['goodsvalue']}}</option>
							</select>
						</td>
						<td>
							附加价格
							<input type="text" name="added[{{$v['type_tid']}}][]" id="" value="{{$v['added']}}">
							<button type="button" id="btn">添加规格</button>
						</td>
					</tr>
					{{endif}}
				{{endforeach}}
				</table>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商品名称</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="gname" value="{{$goodsData['gname']}}">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商品货号</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="gnum" value="{{$goodsData['gnum']}}">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">单位</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="unit" value="台" value="{{$goodsData['unit']}}">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">市场价</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="marketprice" value="{{$goodsData['marketprice']}}">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商城价</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="shopprice" value="{{$goodsData['shopprice']}}">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">总库存</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="" name="stock" value="{{$goodsData['stock']}}">
			</div>
			
			
			<div class="form-group">
				<label for="exampleInputEmail1">列表图</label>
				<div lab="uploadFile">
					<input id="f" type="file" multiple="true">
					<div id="uploadList">
				        <ul>
				        	{{foreach from="$goodsData['listView']" value="$v"}}
							<li style='list-style:none;float:left'>
								<img src="{{$v}}" alt="" width="100px" class="img">
								<a href="javascript:;" class="close_img">×</a>
								<input type="hidden" name="listView[]" value="{{$v}}">
							</li>
				        	{{endforeach}}
				        </ul>
				    </div>
			    </div>
			</div>
			<div class="form-group" style="clear:both">
				<label for="exampleInputEmail1">商品图册</label>
				<div lab="uploadFile">
					<input id="fi" type="file" multiple="true">
					<div id="uploadListf">
				        <ul>
				        {{foreach from="$goodsData['img']" value="$v"}}
							<li style='list-style:none;float:left' class="img_box">
								<img src="{{$v}}" alt="" width="100px">
								<a href="javascript:;" class="close_img">×</a>
								<input type="hidden" name="img[]" value="{{$v}}">
							</li>
						{{endforeach}}
				        </ul>
				    </div>
			    </div>
			</div>
			<div class="form-group" style="clear:both">
				<label for="exampleInputEmail1">商品详细</label>
				<!--调用百度编辑器-->
				<script id="editor" type="text/plain" style="width:100%;height:200px;" name="intro">{{$goodsData['intro']}}</script>
			    <script>
			        var ue = UE.getEditor('editor');
			    </script>
			</div>
			<input type="hidden" name="gid" value="{{$goodsData['gid']}}">
			<input type="hidden" name="did" value="{{$goodsData['did']}}">
			<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
		</form>
	</body>
</html>